﻿namespace DimensionsHelper.Client.WinUi.Views;

public sealed partial class QueryPage : Page
{
    public QueryPage()
    {
        ViewModel = App.GetService<QueryViewModel>();
        ViewModel.IsQueryFinishedHandled = true;

        InitializeComponent();

        if (ViewModel.ValueType == DataCollectionQueryCategoryDataType.Name)
        {
            CategoryNameMenuFlyoutItem.IsChecked = true;
        }
        else
        {
            CategoryValueMenuFlyoutItem.IsChecked = true;
        }

        if (!DataCollectionHelper.IsDataCollectionFound)
        {
            ProviderInvalidInfoGrid.Visibility = Visibility.Visible;
            ProviderInvalidInfoTextBlock.Text =
                string.Format(ResourceKeys.AppRequiredSqlProviderIsNotInstalled.GetLocalized(),
                    DataCollectionHelper.DbProviderDescription);
        }
    }

    public QueryViewModel ViewModel
    {
        get;
    }

    private void CategoryNameMenuFlyoutItem_Click(object sender, RoutedEventArgs e) =>
        ViewModel.ValueType = DataCollectionQueryCategoryDataType.Name;

    private void CategoryValueMenuFlyoutItem_Click(object sender, RoutedEventArgs e) =>
        ViewModel.ValueType = DataCollectionQueryCategoryDataType.Value;
}